import { Component, OnInit, HostBinding, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { NewTaskComponent } from '../new-task/new-task.component';
import { MatDialog } from '@angular/material';
import { CopyTaskComponent } from '../copy-task/copy-task.component';
import { ConfirmComponent } from 'src/app/shared/confirm/confirm.component';
import { NewTaskListComponent } from '../new-task-list/new-task-list.component';
import { slideToRight } from 'src/app/animate/routing.anim';

@Component({
  selector: 'task-task-home',
  templateUrl: './task-home.component.html',
  styleUrls: ['./task-home.component.scss'],
  animations: [
    slideToRight
  ],
  // 对于笨组件 所有的状态改变都是来自于输入属性 值边他才会变
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class TaskHomeComponent implements OnInit {
  @HostBinding('@routeAnim') state;
  lists = [
    {
      id: 1,
      name: '待办',
      order:1,
      tasks: [
        {
          id: 1,
          desc: '任务一：去星巴克买杯咖啡',
          completed: true,
          priority: 3,
          owner: {
            id: 1,
            name: '张三',
            avator: 'avators:svg-11'
          },
          dueDate: new Date(),
        },
        {
          id: 2,
          desc: '任务二：完成布置的PPT作业完成布置的PPT作业',
          completed: false,
          priority: 2,
          owner: {
            id: 2,
            name: '刘洋',
            avator: 'avators:svg-5',
          },
          dueDate: new Date(),
        },
        {
          id: 3,
          desc: '任务三：完成布置的PPT作业',
          completed: false,
          priority: 1,
          owner: {
            id: 3,
            name: '杨阳洋',
            avator: 'avators:svg-1',
          },
          dueDate: new Date(),
          reminder: new Date()
        },
      ]
    }, {
      id: 2,
      name: '进行中',
      order:2,
      tasks: [
        {
          id: 1,
          desc: '任务四：项目测试',
          priority: 3,
          completed: true,
          owner: {
            id: 1,
            name: '李洋',
            avator: 'avators:svg-7',
          },
          dueDate: new Date(),
          reminder: new Date()
        },
        {
          id: 2,
          desc: '任务五：指定项目计划',
          completed: false,
          priority: 2,
          owner: {
            id: 2,
            name: '周倩',
            avator: 'avators:svg-5',
          },
          dueDate: new Date(),
          reminder: new Date()
        },
        {
          id: 3,
          desc: '任务六：完成布置的PPT作业',
          completed: false,
          priority: 1,
          owner: {
            id: 3,
            name: '杨阳洋',
            avator: 'avators:svg-1',
          },
          dueDate: new Date(),
          reminder: new Date()
        },
      ]
    }, {
      id: 3,
      name: '完成',
      order:3,
      tasks: [
        {
          id: 1,
          desc: '任务7：项目测试',
          priority: 3,
          completed: true,
          owner: {
            id: 1,
            name: '李洋',
            avator: 'avators:svg-7',
          },
          dueDate: new Date(),
          reminder: new Date()
        },
        {
          id: 2,
          desc: '任务8：指定项目计划',
          priority: 2,
          completed: false,
          owner: {
            id: 2,
            name: '周倩',
            avator: 'avators:svg-5',
          },
          dueDate: new Date(),
          reminder: new Date()
        },
        {
          id: 3,
          desc: '任务9：完成布置的PPT作业',
          completed: false,
          priority: 1,
          owner: {
            id: 3,
            name: '杨阳洋',
            avator: 'avators:svg-1',
          },
          dueDate: new Date(),
          reminder: new Date()
        },
      ]
    }
  ];
  constructor(private dialog: MatDialog, private cd: ChangeDetectorRef) { }

  ngOnInit() {
  }
  newTaskDialog() {
    const dialogRef = this.dialog.open(NewTaskComponent, { data: { title: '新增任务' } });
  }
  copyTask() {
    const dialogRef = this.dialog.open(CopyTaskComponent, { data: { lists: this.lists } });
  }
  editTaskDialog(task) {
    const dialogRef = this.dialog.open(NewTaskComponent, { data: { title: '修改任务', task: task } });
  }
  deleteProjectDialog() {
    const dialogRef = this.dialog.open(ConfirmComponent, { data: { title: '删除任务', content: '确定要删除该任务吗？' } });
  }
  editListDialog() {
    const dialogRef = this.dialog.open(NewTaskListComponent, { data: { title: '修改列表名称' } });
  }
  newListDialog() {
    const dialogRef = this.dialog.open(NewTaskListComponent, { data: { title: '新建列表' } });
  }
  handleMove(srcData, list) {
    switch (srcData.tag) {
      case 'task-item':
        console.log('处理 item');
        break;
      case 'task-list':
        console.log('处理 list');
        const srcList = srcData.data;
        const tempOrder = srcList.order;
        srcList.order = list.order;
        list.order = tempOrder;
        break;
      default:
        break;
    }
  }
  handleQuickTask(desc:string){
    console.log(desc);
  }
  onClick(){
    
  }
}
